package com.hectopascal.goalance.repository;

import com.hectopascal.goalance.pojo.SystemSetting;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface SystemSettingRepository extends CrudRepository<SystemSetting,Integer> {
    @Query(value = "SELECT * FROM system_settings", nativeQuery = true)
    Optional<List<SystemSetting>> findSystemSettingById();

    @Modifying
    @Transactional
    @Query(value = """
            UPDATE system_settings SET 
            approval_timeout = :approval_timeout 
            WHERE id = :id
       """, nativeQuery = true)
    int updateSystemSetting(@Param("approval_timeout")Integer approvalTimeout,
                            @Param("id") Integer id
    );
}
